<?php
$week_num = $_GET['week_num'];
if (!isset($week_num) || !($week_num >= 0)) die();

include_once('database.php');
$sql = "SELECT day,section,name,location FROM courses WHERE 1=1 ";
if ($week_num > 0) {
	$sql .= "and week_number=${week_num}";
}

$result = @mysqli_query($connection, $sql) or die("查询课程表失败: ".mysqli_error($connection));
$courses = result_to_array($result);

$o = new stdClass();
$o->week_num = $week_num;
$o->courses = $courses;

die(json_encode($o));
?>